from interface.MemberInterface import MemberInterface
from utils.SendMethod import SendMethod


class CartInterface:
    def __init__(self, url, headers):
        self.url = url
        self.headers = headers

    def cart_add(self, payload):
        method = "post"
        url = self.url + "/cart/add"
        return SendMethod.sendmethod(method=method, url=url, json=payload, headers=self.headers)


if __name__ == '__main__':
    url = "http://47.108.206.100:8085"
    headers = MemberInterface(url).get_member_token("Anna", "anna123")
    print(headers)
    cart = CartInterface(url, headers)
    payload = {
        "createDate": "2022-06-10T02:01:35.734Z",
        "deleteStatus": 1,
        "id": 22,
        "memberId": 1853,
        "memberNickName": "Anna",
        "modifyDate": "2022-06-10T04:01:35.734Z",
        "quantity": 1,
        "price": 2699,
        "productAttr": '[{"key":"颜色","value":"黑色"},{"key":"容量","value":"32G"}]',
        "productBrand": "小米",
        "productCategoryId": 19,
        "productId": 27,
        "productName": "小米8 全面屏游戏智能手机 6GB+64GB 黑色 全网通4G 双卡双待",
        "productPic": "http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20180615/xiaomi.jpg",
        "productSkuCode": "2201808270027001",
        "productSkuId": 98,
        "productSn": "7437788",
        "productSubTitle": "骁龙845处理器，红外人脸解锁，AI变焦双摄，AI语音助手小米6X低至1299，点击抢购"

    }
    print(cart.cart_add(payload))  # 调用添加购物车
